/*=====================================================================

  File:      Pair.cs
  Summary:   A small utility class that represents a pair of values
  Date:	     May 27, 2007

---------------------------------------------------------------------

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= */

using System;

namespace Microsoft.Samples.SqlServer.DB3D
{
	/// Generic representation of a pair of values. The first value is used
	/// for the string conversion, making it also useful for some UI controls

    public class Pair<T1,T2> where T1: IComparable where T2: IComparable
    {
        T1 _v1;
        T2 _v2;

        public Pair() {
        }

        public Pair(T1 v1, T2 v2) {
            _v1 = v1;
            _v2 = v2;
        }

        public T1 Value1 {
            get { return _v1; }
            set { _v1 = value; }
        }

        public T2 Value2 {
            get { return _v2; }
            set { _v2 = value; }
        }

        // display only v1, this makes this also useful for some UI controls
        public override string ToString() {
            return _v1.ToString();
        }

        public override bool Equals(object obj) {
            Pair<T1,T2> pair = obj as Pair<T1,T2>;

            if(null == pair)
                return false;

            return _v1.CompareTo(pair._v1) == 0 && _v2.CompareTo(pair._v2) == 0;
        }

        public override int GetHashCode() {
            // this is a simplification, specific scenarios may require smarter
            // ways of computing the hash-value
            return _v1.GetHashCode() + _v2.GetHashCode();
        }
    }
}
